﻿import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.15
import Qt.labs.settings 1.0

// 导入自定义包
import com.mycompany.customType 1.0

Item {
    visible: true
    width: 480
    height: 400

    property alias searchBtn: searchBtn
    property alias textFieldPort: textFieldPort
    property alias listViewServer: listViewServer

    // 字体加载


    /*FontLoader {
        id: customFont;
        source: "/font/SourceHanSansCN-Normal.otf"
    }
    // 设置字体,默认字体手机端中文显示有问题
    font{family: customFont.name; pixelSize: 14}
    */
    Settings {// 保存配置
        property alias ftpPortText: textFieldPort.text
    }

    Page {
        anchors.fill: parent
        header: ToolBar {
            height: 30
            width: parent.width
            RowLayout {
                anchors.fill: parent
                ToolButton {
                    id: searchBtn
                    height: parent.height
                    width: 50 //parent.height * 3
                    text: qsTr("搜索")


                    /*icon.source: {
                            if(0 === swipeView.currentIndex)
                            {
                                return "/image/refresh.png"
                            }
                            return "/image/menuBtn.png"
                        }*/
                    //display: AbstractButton.IconOnly
                    font.pixelSize: Qt.application.font.pixelSize * 1
                    contentItem: Text {
                        text: parent.text
                        font: parent.font
                        opacity: parent.enabled ? 1.0 : 0.3
                        color: parent.down ? "#17a81a" : "#21be2b"
                        horizontalAlignment: Text.AlignHCenter
                        verticalAlignment: Text.AlignVCenter
                        elide: Text.ElideRight
                    }
                    background: Rectangle {
                        implicitWidth: parent.width
                        implicitHeight: parent.height
                        opacity: parent.enabled ? 1 : 0.3
                        border.color: parent.down ? "#17a81a" : "#21be2b"
                        border.width: 1
                        radius: 2
                    }
                }

                Label {
                    //id: labelWebTitle
                    text: qsTr("FTP服务器列表")
                    elide: Label.ElideRight
                    height: parent.height
                    horizontalAlignment: Qt.AlignHCenter
                    verticalAlignment: Qt.AlignVCenter
                    //anchors.centerIn: parent
                    Layout.fillWidth: true
                }
                Label {
                    text: qsTr("FTP端口:")
                    elide: Label.ElideRight
                    height: parent.height
                    horizontalAlignment: Qt.AlignRight
                    verticalAlignment: Qt.AlignVCenter
                }
                TextField {
                    id: textFieldPort
                    width: 50
                    height: 30
                    text: qsTr("2121")                    
                    horizontalAlignment: Text.AlignHCenter
                    Layout.preferredHeight: 30
                    Layout.preferredWidth: 50
                    placeholderText: qsTr("端口")
                }
            }
        }
        contentData: ListView {
            id: listViewServer
            anchors.fill: parent
            focus: true
            cacheBuffer: 1000000000 // 这个值不能太小，否则itemAtIndex会获取值为空，遍历的时候就会失败
            headerPositioning: ListView.OverlayHeader
            delegate: delegateServerList
            //model: bluetoothDeviceModel
            //model: BluetoothDeviceModelSingleton
            model: ServerListModel {
                id: serverListModel
                objectName: "serverListModel"
            }
            highlight: highlightDevice
            highlightFollowsCurrentItem: false
        }
    }
}
